package trans;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * @ClassName Myframe
 * @Description TODO
 * @Author WSY
 * @Date 2020-6-3 17:19
 */

public class Myframe extends JFrame {

    Dictionary d = new Dictionary();

    private JTextField input;

    private LinkedList<Main> content = new LinkedList<>();

    private JButton add = new JButton("添加");

    JTextField cinput = new JTextField();

    JTextField einput = new JTextField();

    public Myframe() {
        Main r1 = new Main("age", "年龄");
        Main r2 = new Main("name", "姓名");
        Main r3 = new Main("hello", "你好");
        content.add(r1);
        content.add(r2);
        content.add(r3);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        JPanel contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        input = new JTextField();
        input.setBounds(37, 34, 235, 28);
        contentPane.add(input);
        input.setColumns(10);

        JTextArea output = new JTextArea();
        output.setBounds(37, 72, 235, 161);
        contentPane.add(output);
        JButton search = new JButton("search");
        search.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String str =d.search(input.getText());
                output.setText(str);

            }
        });
        add.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                d.add(einput.getText(),cinput.getText());
                JOptionPane.showMessageDialog(add,"添加成功","成功",JOptionPane.INFORMATION_MESSAGE);

            }
        });
        search.setBounds(310, 33, 100, 29);
        contentPane.add(search);
        add.setBounds(310, 200, 100, 29);
        contentPane.add(add);
        cinput.setBounds(310, 80, 100, 29);
        einput.setText("英");
        contentPane.add(cinput);
        einput.setBounds(310, 140, 100, 29);
        cinput.setText("中");
        contentPane.add(einput);
        setLocationRelativeTo(null);
    }

}
